/*
 * UPSceneInspector.java
 *
 * Created on 2010-09-01, 20:37:57
 */

package JET.UtilPanels;

import JET.Centers.ControlCenter;
import JET.Centers.Graphics.GUICenter;
import JET.Frames.DataModels.DataModelsFactory;
import JET.Frames.DataModels.SceneTreeModel;
import JET.Scene;
import JET.UtilPanels.Trees.SceneTree;
import JET.UtilPanels.Trees.SceneTreeCellRenderer;
import JET.mygui.UtilTabsPane.UtilTabsPaneTab;
import java.awt.event.ItemEvent;
import java.awt.event.MouseEvent;

/**
 *
 * @author 057Ry
 */
public class UPSceneInspector extends javax.swing.JPanel implements UtilTabsPaneTab {

    static final ControlCenter CC = ControlCenter.getInstance();

    /** Creates new form UPSceneInspector */
    public UPSceneInspector() {
        initComponents();
        sceneTree.setCellRenderer(new SceneTreeCellRenderer());
    }

    public GUICenter.UtilTabs getId() {
        return GUICenter.UtilTabs.SceneInspector;
    }

    public boolean isScrollable() {
        return false;
    }

    /**
     * Makes specified scene as active inspected in scene tree.
     * @param sceneName Name of a scene to inspect.
     */
    public void setScene(Scene scene) {
        SceneTreeModel model = (SceneTreeModel)sceneTree.getModel();
        model.setScene(scene);
        model.fireWholeTreeChanged();

        getSceneTree().setScene(scene);
    }

    public void updateSceneTreeUI() {
        sceneTree.updateUI();
    }

    public SceneTree getSceneTree() {
        return (SceneTree) sceneTree;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        sceneTreePopupMenu = new javax.swing.JPopupMenu();
        autorefreshCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
        jScrollPane1 = new javax.swing.JScrollPane();
        sceneTree = new SceneTree();

        autorefreshCheckBoxMenuItem.setText("Auto refresh");
        autorefreshCheckBoxMenuItem.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                autorefreshCheckBoxMenuItemItemStateChanged(evt);
            }
        });
        sceneTreePopupMenu.add(autorefreshCheckBoxMenuItem);

        sceneTree.setModel(DataModelsFactory.getSceneTreeModel());
        sceneTree.setToolTipText("Gives access to scene elements");
        sceneTree.setEditable(true);
        sceneTree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                sceneTreeMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(sceneTree);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
        );

        getAccessibleContext().setAccessibleName("Scene Inspector");
    }// </editor-fold>//GEN-END:initComponents

    private void sceneTreeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sceneTreeMouseClicked
        if (evt.getClickCount() == 1 && evt.getButton() == MouseEvent.BUTTON3)
            sceneTreePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
    }//GEN-LAST:event_sceneTreeMouseClicked

    private void autorefreshCheckBoxMenuItemItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_autorefreshCheckBoxMenuItemItemStateChanged
        getSceneTree().setAutorefresh(evt.getStateChange() == ItemEvent.SELECTED);
    }//GEN-LAST:event_autorefreshCheckBoxMenuItemItemStateChanged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBoxMenuItem autorefreshCheckBoxMenuItem;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTree sceneTree;
    private javax.swing.JPopupMenu sceneTreePopupMenu;
    // End of variables declaration//GEN-END:variables
}
